<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm" th:object="${appVersion}">
                        <input type="hidden" th:value="${appVersion.id}" name="id"/>
                        <input name="orgId"  type="hidden" th:value="${appVersion.orgId}" id="treeId"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属机构：</label>
                            <div class="col-sm-8">
                                <input class="form-control" th:value="${appVersion.orgName}" type="text" name="orgName" onclick="selectDeptTree()" readonly="true" id="orgName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>安卓版本号：</label>
                            <div class="col-sm-8">
                                <input id="androidVersion" th:value="${appVersion.androidVersion}" name="androidVersion" data-null="请输入安卓版本号" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">安卓是否强制升级：</label>
                            <div class="col-sm-8">
                                <select id="androidUpdate" name="androidUpdate" class="form-control m-b" th:with="type=${@dict.getType('version_update')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{androidUpdate}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">安卓下载URL：</label>
                            <div class="col-sm-8">
                                <input type="file" onchange="uploadFile(this)" id="upFile" name="upFile" multiple="multiple" class="form-control" accept="image/*"/>
                                <input id="androidDownload" th:value="${appVersion.androidDownload}" name="androidDownload" type="hidden">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">安卓升级描述：</label>
                            <div class="col-sm-8">
                                <input id="androidDescribe" th:value="${appVersion.androidDescribe}" name="androidDescribe" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>IOS版本号：</label>
                            <div class="col-sm-8">
                                <input id="iosVersion" th:value="${appVersion.iosVersion}" name="iosVersion" data-null="请输入IOS版本号" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">IOS是否强制升级：</label>
                            <div class="col-sm-8">
                                <select id="iosUpdate" name="iosUpdate" class="form-control m-b" th:with="type=${@dict.getType('version_update')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{iosUpdate}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">IOS下载地址：</label>
                            <div class="col-sm-8">
                                <input id="iosDownload" th:value="${appVersion.iosDownload}" name="iosDownload" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">IOS升级描述：</label>
                            <div class="col-sm-8">
                                <input id="iosDescribe" th:value="${appVersion.iosDescribe}" name="iosDescribe" class="form-control" type="text">
                            </div>
                        </div>
                        <!-- 附加信息结束 -->
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <div class="btn btn-primary" onclick="save()">提交</div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>

    function uploadFile(obj) {
        var form = new FormData();
        var fileObj = obj.files[0];
        form.append("upFile",fileObj);
        $.ajax({
            type:"post",
            data:form,
            url:ctx+"appVersion/upload",
            contentType: false, //必须false才会自动加上正确的Content-Type
            processData: false,
            success:function(data){
                parent.layer.alert(data.msg);
                $("#androidDownload").val(data.msg);
            }
        });
    }

    function save() {
        // 必输校验
        var hasFlag = 0;
        $('#signupForm input').each(function (index, item) {
            var val = $.trim($(item).val());
            var dataNull = $(item).data('null');
            if (!val && !hasFlag && dataNull) {
                hasFlag = 1;
                layer.msg(dataNull);
            }
        })
        if (hasFlag) {
            return;
        }
        $.ajax({
            cache: true,
            type: "POST",
            url:  ctx+"appVersion/editAppVersion",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("网络超时");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
    }

    /*选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "system/dept/selectDeptTree/" + deptId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#orgName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
</body>
</html>
